package org.tinaelle.client.utils;

public class Currency {

	private final static String	unit	= "USD";

	private final float	        val;

	public Currency(final float val) {
		super();
		this.val = val;
	}

	public String getFormated() {
		// what is an elegant way of formating floats in GWT as
		// String.format() doesn't exist??
		final int i = ( int ) ( val * 100 );
		if ( ( i % 100 ) == 0 ) {
			return String.valueOf( i / 100 ) + ".00";
		}
		if ( ( i % 10 ) == 0 ) {
			return String.valueOf( i / 100.0f ) + "0";
		} else {
			return String.valueOf( i / 100.0f );
		}
	}

	public String getFormatedWithUnit() {
		return getFormated() + " " + unit;
	}

	@Override
	public String toString() {
		return getFormatedWithUnit();
	}

	public static String format(final float val) {
		return new Currency( val ).toString();
	}

}
